<?php

declare(strict_types=1);

namespace App\Model\PssModel;

use App\Model\BaseModel\BasePssModel;
use Hyperf\DbConnection\Db;
class OrderRefundGoods extends BasePssModel
{
    public $table = 'order_refund_goods';
    
    /**
     * 统计已售后的商品数据
     * @param string $order_id
     * @param array $skucodes
     */
    public function getByGoodsRefundItems(string $order_id,array $skucodes)
    {
        return self::query()
        ->select([
            'skucode',
            'spec_num',
            Db::raw("count(1) AS total_refund_goods_count"),
        ])
        ->where('order_id',$order_id)
        ->whereIn('skucode',$skucodes)
        ->where('refund_useable',1)
        ->groupBy('skucode')
        ->groupBy('spec_num')
        ->get()
        ->toArray();
    }
}
